package ru.study.jdbc.orm;

import java.util.Arrays;

import ru.study.jdbc.entity.AbstractEntity;

public class OrmManager <T extends IOrm> {	
	
	private OrmManager() {};	
	
	/*private static IOrm getStudentOrm() {
		return  StudentOrm.getInstance();
	}
	private static IOrm getGroupOrm() {
		return  GroupOrm.getInstance();
	}*/
	
	public static IOrm getOrmByClass(Class c) {
		IOrm orm =  new EmptyOrm();
		Class[] cc = c.getInterfaces();
		for (Class clazz : cc) {			
			if (clazz.isAssignableFrom(AbstractEntity.class)) {
				try {
					AbstractEntity ae = (AbstractEntity) c.newInstance();					
					orm = ae.getOrmDescription();
				} catch (Exception e) {
					e.printStackTrace();
				}				
				break;
			}				
		}		
		return orm;
	}
}
